#pragma once
#include<iostream>
#include<assert.h>

namespace gm
{
	class string
	{
	public:

		//string()
		//{
		//	_size = 0;
		//	_capacity = 0;
		//	_str = new char ('\0');
		//}

		typedef char* iterator;

		iterator begin()
		{
			return _str;
		}

		iterator end()
		{
			return _str + _size ;
		}

		string(const char* str = "")
		{
			_size = strlen(str);
			_capacity = _size;
			_str = new char [_capacity +1];

			strcpy(_str, str);
		}

		~string()
		{
			delete[] _str;
			_str = nullptr;
			_capacity = 0;
			_size = 0;
		}

		const char* c_str()
		{
			return _str;
		}

		size_t size()
		{
			return _size;
		}

		char& operator[] (size_t pos)
		{
			assert(pos <= _size);
			return _str[pos];

		}

	private:
		char* _str;
		size_t _capacity ;
		size_t _size;
	};

	void test_string1()
	{
		string s1("hello world");
		cout << s1.c_str() << endl;

		string s2;
		cout << s2.c_str() << endl;

		for (size_t i = 0; i < s1.size(); i++)
		{
			s1[i]++;
		}
		cout << s1.c_str() << endl;

		string::iterator it = s1.begin();
		while (it != s1.end())
		{
			cout << *it << " ";
			++it;
		}
		cout << endl;

	}

}
